/**
 * 
 */
package mediasManagement;

import java.util.Hashtable;

import exceptions.BadParametersException;
import exceptions.MediaExistsException;

/** 
 * @author virgil
 */
public class FabricCategory {

	/**
	 * create a dictionnary of categories
	 * @uml.property  name="categories"
	 */
	private Hashtable<String, Category> categories = new Hashtable<String, Category>();

	
		
		/**
		 * check if a category already exists or no.if no, create this category
		 * @throws BadParametersException 
		 */
	public Category getCategory(String nameCategory) throws BadParametersException{
		
		Category result;
		if(categories.containsKey(nameCategory)){
			result = categories.get(nameCategory);
			}
		else
			result= new Category(nameCategory);
			categories.put(nameCategory,result);
		return result;
		}
    /**
     * check if a category already exists or no.if no, create this category
     *  put a media in this category
     * @param nameCategory
     * @param media
     * @return
     * @throws BadParametersException
     * @throws MediaExistsException
     */
	public Category getCategory(String nameCategory,Media media) throws BadParametersException, MediaExistsException{
		
		Category result;
		
		if(categories.containsKey(nameCategory)){
			result = categories.get(nameCategory);
			result.addMedia(media);
			categories.put(nameCategory, result);
			}
		else{
			result= new Category(nameCategory,media);
			categories.put(nameCategory,result);
			}
		return result;
	
		}

			

}
